package subsetXORSum;

import java.util.Stack;

public class Solution {
    private int sum = 0;
    public int subsetXORSum(int[] nums) {
        for (int i = 1; i < nums.length; i++) {
            trackBack(0,i,nums,0,new Stack<>());
        }
        return sum;
    }
    private void trackBack(int start,int k,int[] nums,int xor,Stack<Integer> stack){
        if(stack.size() == k){
            sum+=xor;
        }
        for (int i = start; i < nums.length -( k - stack.size())+1; i++) {
            xor^=nums[i];
            stack.push(nums[i]);
            trackBack(i+1,k,nums,xor,stack);
            stack.pop();
            xor^=nums[i];
        }
    }
}
